package models

import (
	"time"
)

type StudentPact struct {
	Id       int       `xorm:"not null pk autoincr INT(11)"`
	SchoolId int       `xorm:"INT(11)"`
	CarType  string    `xorm:"VARCHAR(255)"`
	Content  string    `xorm:"TEXT"`
	Addtime  time.Time `xorm:"DATETIME"`
}

func (m *StudentPact) GetPact(school_id, car_type string) (list []*StudentPact, err error) {
	err = engine.Table("dts_student_pact").
		Where("school_id = ? and car_type = ?", school_id, car_type).
		Find(&list)
	return
}

func (c *StudentPact) Add() bool {
	if _, err := engine.Insert(c); err != nil {
		return false
	}
	return true
}

func (c *StudentPact) Edit(fields ...string) bool {
	var (
		err error
	)
	_, err = engine.ID(c.Id).Cols(fields...).Update(c)
	if err != nil {
		return false
	}
	return true
}
